import * as type from './actionTypes'
import Auth from '@/auth/Auth'

const reducerFun = (state = {
    isFetching: false,
    isAuthenticated: Auth.getToken() ? true : false
  }, action) => {
    switch (action.type) {
        case type.LOGIN_REQUEST:
        return Object.assign({}, state, {
          isFetching: true,
          isAuthenticated: false,
        //   user: action.creds
        })
      case type.LOGIN_SUCCESS:
        return Object.assign({}, state, {
          isFetching: false,
          isAuthenticated: true,
          user: action.user,
          errorMessage: ''
        })
      case type.LOGIN_FAILURE:
        return Object.assign({}, state, {
          isFetching: false,
          isAuthenticated: false,
          errorMessage: action.message
        })
      default:
        return state
    }
}

export default reducerFun;